package java6699.lesson13;

/**
 * @program: java_zzx
 * @description:
 * @author: zzx
 * @create: 2022-11-28 10:24
 **/
public class DrinkWater6699 {
    private static int waters;

    public static void main(String[] args) {
        waters = 20;
        new Thread(DrinkWater6699::drinking6699, "狗").start();
        new Thread(DrinkWater6699::drinking6699, "猫").start();
    }

    static void drinking6699() {
        String name = Thread.currentThread().getName();
        while (waters > 0) {
            if (name.equals("狗")) {
                waters = waters - 5;
            } else if (name.equals("猫")) {
                waters = waters - 2;
            }
            System.out.println(name + "已喝水，剩" + waters);
        }
        System.out.println(name + "请加水！！");
    }
}
